<?php


namespace app\api\model;


use think\Db;

class Draw extends Base
{
    public function doesItExist($data)
    {
        $name = 'draw_'.date('Ym',strtotime($data['draw_time']));
        $result = Db::name($name)->where(['order_no'=>$data['order_no'],'org_id'=>$data['org_id'],'app_id'=>$data['app_id']])->find();
        return $result;
    }

    public function saveData($data)
    {
        $name = 'draw_'.date('Ym',strtotime($data['draw_time']));
        $param['org_id'] = $data['org_id'];
        $param['app_id'] = $data['app_id'];
        $param['user_id'] = $data['user_id'];
        $param['draw_time'] = $data['draw_time'];
        $param['money'] = $data['money'];
        $param['order_no'] = $data['order_no'];
        $save  = Db::name($name)->insert($param);
        if ( $save == 0 || $save == false) {
            $res=[  'code'=> 1001,  'msg' => '数据保存失败', ];
        }else{
            $res=[  'code'=> 1000,  'msg' => '数据保存成功',  ];
        }
        return $res;
    }
}